import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Like
 * Date: 2021-07-14
 * Time: 9:05
 */

public class FatherClass {
    public FatherClass(int i) {
        System.out.println("im quick sort");
    }

    public FatherClass() {
    }

    public static void quickSort(int[] arr){
        //经典判空
        if(arr==null || arr.length==0 || arr.length==1) {
            return;
        }
        int left=0;
        int right=arr.length-1;

        sort(arr,left,right);
    }

    public static void sort(int[] arr, int left,int right){
        if (left>right) {
            return;
        }

        int i =left;
        int j= right;
        int pivot= arr[left];


        while (i!=j){
            while (arr[j]>=pivot && j>i) {
                j--;
            }
            while (arr[i]<=pivot && j>i) {
                i++;
            }

            if (i<j)
            {
            int c=arr[j];
            arr[j]=arr[i];
            arr[i]=c;}


        }
        arr[left]=arr[i];
        arr[i]=pivot;

        sort(arr,left,i-1);
        sort(arr,i+1,right);

    }
    public static void main(String[] args) {
        int[] arr;

        arr=new int[]{5,4,3,2,1};
        int[] arr2 = arr.clone();
        quickSort(arr2);
        System.out.println(Arrays.toString(arr));
        System.out.println(Arrays.toString(arr2));
    }
}
